package com.gcxy.controller;


import com.gcxy.dto.Ranch.InsertDto;
import com.gcxy.dto.Ranch.RanchPageDto;
import com.gcxy.dto.Ranch.UpdateDto;
import com.gcxy.service.RanchService;
import com.gcxy.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wlp
 * @since 2023-12-19
 */
@RestController
@RequestMapping("/ranch")
@Api(tags = "牧场管理")
public class RanchController {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private RanchService ranchService;

    @ApiOperation("新增牧场")
    @PostMapping("getRanch")
    public R getRanch(@Valid @RequestBody InsertDto requestBody) {
        logger.info("正在新增牧场");
        R result = ranchService.getRanch(requestBody);
        return result;
    }
    @ApiOperation("修改牧场")
    @PutMapping("updataRanch")
    public R updateRanch(@Valid @RequestBody UpdateDto requestBody){
        logger.info("正在修改牧场信息");
        R result=ranchService.updateRanch(requestBody);
        return result;
    }
    @ApiOperation("分页查询牧场")
    @PostMapping("page")
    public R pageRanch(@RequestBody RanchPageDto requestBody){
        logger.info("正在分页查询牧场");
        R result=ranchService.pageRanch(requestBody);
        return result;
    }
    @ApiOperation("牧场启用/停用")
    @PutMapping("updataRanchState/{ranchId}/{ranchState}")
    public R updateRanchState(@PathVariable Integer ranchId,@PathVariable Integer ranchState){
        logger.info("正在修改牧场状态");
        R result=ranchService.updateRanchState(ranchId,ranchState);
        return result;
    }
}

